//
//  AmbitusDetailTestCell.m
//  TravelToHelp
//
//  Created by lanou3g on 15/10/30.
//  Copyright © 2015年 冯贵宾. All rights reserved.
//

#import "AmbitusDetailTestCell.h"

@interface AmbitusDetailTestCell ()

@property (nonatomic, strong) UILabel *titleLable;

@end

@implementation AmbitusDetailTestCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)  {
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
        
        self.titleLable.font = [UIFont systemFontOfSize:15];
        self.titleLable.numberOfLines = 0;
        [self.contentView addSubview:self.titleLable];
        
    }
    return self;
}


- (void)setModel:(AmbitusDetailModel *)model
{
    
    CGRect newFrame = self.titleLable.frame;
    newFrame.size.height = [AmbitusDetailTestCell cellHeightWithModel:model.content font:15];
    self.titleLable.frame = newFrame;
    self.titleLable.text = model.content;
}

+ (CGFloat)cellHeightWithModel:(NSString *)str font:(NSInteger)font
{
    // 计算字符串高度
    // 字号一定与lable相等
    if (str.length > 0) {
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:font] forKey:NSFontAttributeName];
       
        CGRect lableFrame = [str boundingRectWithSize:CGSizeMake(kScreenWidth , 100000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
        return lableFrame.size.height;

    }
    return 0;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
